<template>
  <div class="record">
    <div class="content">
      <!-- 顶部搜索 -->
      <div class="toolbar">
        <el-form ref="formParams" :inline="true" :model="formParams" :rules="rules">
          <el-form-item label="用户ID/用户昵称" prop="search">
            <el-input v-model="formParams.search" maxlength="20" placeholder="请输入用户ID/用户昵称" />
          </el-form-item>
          <el-form-item label-width="0">
            <el-button type="primary" plain @click="search('formParams')">查询</el-button>
            <el-button plain @click="clear('formParams')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <!-- 表格 -->
      <div class="content_table">
        <div class="table">
          <el-table
            :data="list"
            border
            :header-cell-style="{ background: '#EEF3FF', color: '#333333' }"
            style="width: 100%"
          >
            <el-table-column prop="buyerUserId" label="用户ID" />
            <el-table-column prop="name" label="用户昵称" />
            <el-table-column prop="phone" label="用户手机号" />
            <el-table-column prop="recordContent" label="账单标题" />
            <el-table-column prop="recordType" label="类型">
              <template slot-scope="scope">
                <span>{{ scope.row.recordType===1?'收入':scope.row.recordType===2?'支出':'' }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="credit" label="数字明细" />
            <el-table-column prop="remainCredit" label="剩余积分" />
          </el-table>
        </div>
        <!-- 分页 -->
        <div class="fenye">
          <el-pagination
            :current-page="formParams.page"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { recordGetAll } from '@/api/sign'
export default {
  data () {
    return {
      list: [],
      total: 1,
      formParams: {
        page: 1,
        pageSize: 10,
        search: ''
      },
      rules: {
        noticeType: [
          { required: true, message: '请选择消息类型', trigger: 'change' }
        ]
      }
    }
  },
  mounted () {
    this.getAll()
  },
  methods: {
    // 历史消息列表
    async getAll () {
      const res = await recordGetAll(this.formParams)
      this.list = res.data.list
      this.total = res.data.total
    },
    // 查询
    async search (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.total = 1
          this.formParams.page = 1
          this.formParams.search = this.formParams.search.trim()
          this.getAll()
        } else {
          return false
        }
      })
    },
    // 重置表单
    async clear (formName) {
      this.$refs[formName].resetFields()
      this.getAll()
    },
    // 更改页数
    async handleSizeChange (val) {
      this.formParams.pageSize = val
      this.getAll()
    },
    // 翻页
    async handleCurrentChange (val) {
      this.formParams.page = val
      this.getAll()
    },
    // 关闭消息详情
    async handleClose () {
      this.dialogVisible = false
    }
  }
}
</script>

<style lang='scss' scoped>
@import url("../../styles/elDialog.scss");
.record{
  padding: 20px;
}
</style>
<style scoped>
.record /deep/ .el-table .cell.el-tooltip img {
  max-height: 100px;
}
</style>
